/** Interactive Surface  FYP- 25 Interactive Surface FYP- 25 Interactive Surface FYP- 25
 *
 *  @author Acer
 */
package controller;

import camera.ColorMeanCamera;
import insurface.InteractiveSurface;

/** Interactive Surface FYP- 25 Interactive Surface FYP- 25 Interactive Surface FYP- 25
 *  General Information about this class -
 *  Comments -Controls the two cameras
 */
public class ColorMeanController extends Controller {

    public static int[] ty;

    public ColorMeanController(int CAM_NUM1, int CAM_NUM2, InteractiveSurface ins) {
        super(CAM_NUM1, CAM_NUM2, ins);
        int im1 = ins.initializeCamera(CAM_NUM1);
        int im2 = ins.initializeCamera(CAM_NUM2);
        cam1 = new ColorMeanCamera(CAM_NUM1, CAM_FOV, im1);
        cam2 = new ColorMeanCamera(CAM_NUM2, CAM_FOV, im2);
        th1 = new Thread(cam1);
        th2 = new Thread(cam2);
    }

    @Override
    public void run() {
        th1.start();
        th2.start();
        double theta, beeta, gamma, delta;
        int y1, y2;

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        while (camActive) {
            inSurface.setCamera(((ColorMeanCamera) cam1).imTemp, ((ColorMeanCamera) cam1).tempTh, ((ColorMeanCamera) cam1).IMAGE_NO);
            inSurface.setCamera(((ColorMeanCamera) cam2).imTemp, ((ColorMeanCamera) cam2).tempTh, ((ColorMeanCamera) cam2).IMAGE_NO);
            beeta = cam1.getTheta();
            theta = cam2.getTheta();
            delta = Math.toRadians(90) - beeta;
            gamma = Math.toRadians(90 - CAM_FOV) + theta;


            if (theta < Math.toRadians(1) || beeta < Math.toRadians(1)) {
                ty = new int[2];
                ty[0] = -10;
                ty[1] = -10;
            } else {
                ty = coFind.getCoordinate(1, delta, gamma);
            }
            inSurface.setXY(ty[0], ty[1]);


            if (gettingLast) {
                y1 = cam1.getY();
                y2 = cam2.getY();

                yVal1[count] = y1;
                yVal2[count] = y2;
                count++;
                if (count == 50) {
                    setYLast();
                }
            }
        }
    }
}
